<?php

class Contact {

    public $tell;
    public $fax;
    public $add;

    public static function getElementById($nid) {
        $node = node_load($nid);
        if ($node !== FALSE)
            return Contact::toModel($node);
        return NULL;
    }

    public static function getElementsByCategory($tid = NULL, $from = 0, $limit = 2) {
        if ($tid == NULL) {
            $query = new EntityFieldQuery();
            $queryResult = $query->entityCondition('entity_type', 'node')
                    ->propertyCondition('type', 'customer_service')
                    ->propertyOrderBy('created', 'DESC')
                    ->range($from, $limit)
                    ->execute();
        }
        $result = array();
        if (isset($queryResult['node'])) {
            foreach ($queryResult['node'] as $key => $value) {
                $model = Contact::getElementById($key);
                if ($model != NULL)
                    $result[] = $model;
            }
        }
        return $result;
    }

    public static function toModel($node) {
        $model_contact = new Contact();
        
        $tell_contact = field_get_items('node', $node, 'field_tell_company_contact');
        $fax_contact = field_get_items('node', $node, 'field_fax_company_contact');
        $add_contact = field_get_items('node', $node, 'field_address_company_contact');
        if (count($tell_contact) > 0)
            $model_contact->tell = $tell_contact[0]['value'];
            $model_contact->fax = $fax_contact[0]['value'];
            $model_contact->add = $add_contact[0]['value'];
          
        return $model_contact;
    }
    public static function getCountryXml(){
         $xmlCountries =  file_create_url(drupal_get_path_alias('sites/all/library/countries.xml')) ;
       
    $countries = simplexml_load_file($xmlCountries);  
    return $countries;
    }
    public static function getCountry() {
    $countries = Contact::getCountryXml();
    $country_name = array();
    foreach ($countries as $country) {
        $country_name[(string)$country['code']] = (string)$country['name'];
    }
    return $country_name;
}

   

}

?>
